import Vue from 'vue'
import VueRouter from 'vue-router'
// import Reg from '@/views/Reg/Reg.vue'
// import Login from '@/views/login/Login.vue'
// import Main from '@/views/Main/Main.vue'
// import Home from '@/views/home/Home.vue'
// // 开始写基本资料的小组件
// import UserInfo from '@/views/user/Userinfo.vue'
// import UserAvatar from '@/views/user/UserAvatar.vue'
// import UserPwd from '@/views/user/UserPwd.vue'
// // 文章分类
// import Article from '@/views/Menus/Article/Article.vue'
// import ArtList from '@/views/Menus/Article/ArtList.vue'

// 懒加载
// import Reg from '@/views/Reg/Reg.vue'
Vue.use(VueRouter)

const routes = [
  {
    path:'/',
    name:'main',
    component:()=>import('@/views/Main/Main.vue'),
    redirect:'home',  // 重定向到 那个 home组件
    children:[
      {  // main主体区
        path:'home',
        name:'home',
        component:()=>import('@/views/home/Home.vue'),
      },
      {  // 资本资料组件
        path:'/user-info',
        name:'userInfo',
        component:()=>import('@/views/user/Userinfo.vue'),
      },
      {  // 头像 杰尼龟
        path:'/user-avatar',
        name:'userAvatar',
        component:()=>import('@/views/user/UserAvatar.vue'),
      },
      {  // 密码重置 
        path:'/user-pwd',
        name:'userPwd',
        component:()=>import('@/views/user/UserPwd.vue'),
      },
      {  // 增删改查  
        path:'/art-cate',
        name:'art-cate',
        component:()=>import('@/views/Menus/Article/Article.vue'),   //Article
      },
      {  // 发布文章  
        path:'art-list',
        name:'art-list',
        component:()=>import('@/views/Menus/Article/ArtList.vue'),  //ArtList
      },
    ]
  },
  {
    path:'/reg',
    name:'reg',
    component:()=>import('@/views/Reg/Reg.vue'),  //Reg
  },
  {
    path:'/login',
    name:'login',
    component: ()=>import('@/views/login/Login.vue'), //Login
  },
]



//  路由守卫 必须在实例化以后使用 
const router = new VueRouter({
  routes
})
// 保存了原方法 再进行错误捕获 使用了调用构造函数的方法 最后 还是再实例上 实例可以使用 
// 报错原因  从夫跳转了‘/login’ 但是 push原方法 只允许跳转一次
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

export default router
